home *** CD-ROM | disk | FTP | other *** search
/ Champak 125 / Vol 125 (Damaged).iso / games / rabbit_r.swf / scripts / __Packages / smashing / keithm / ViewportGroup.as < prev   
Encoding:
Text File  |  2009-06-09  |  4.3 KB  |  190 lines

  1. class smashing.keithm.ViewportGroup
  2. {
  3.    var name;
  4.    var mcs;
  5.    var index;
  6.    var numSlots;
  7.    var sortAxis;
  8.    var ascending;
  9.    var reverse;
  10.    var scrollport;
  11.    var min;
  12.    var max;
  13.    var current;
  14.    var isSearching;
  15.    var loop;
  16.    function ViewportGroup(t_data)
  17.    {
  18.       this.name = t_data.name;
  19.       this.mcs = [];
  20.       this.index = t_data.index;
  21.       this.numSlots = t_data.slots;
  22.       if(t_data.sortAxis == undefined)
  23.       {
  24.          t_data.sortAxis = "";
  25.       }
  26.       this.sortAxis = t_data.sortAxis;
  27.       if(this.sortAxis != "" && this.numSlots < 10000)
  28.       {
  29.          this.numSlots = 10000;
  30.       }
  31.       if(t_data.ascending == undefined)
  32.       {
  33.          t_data.ascending = false;
  34.       }
  35.       this.ascending = t_data.ascending;
  36.       if(t_data.reverse == undefined)
  37.       {
  38.          t_data.reverse = false;
  39.       }
  40.       this.reverse = t_data.reverse;
  41.       if(t_data.scrollport == undefined)
  42.       {
  43.          t_data.scrollport = false;
  44.       }
  45.       this.scrollport = t_data.scrollport;
  46.    }
  47.    function init(t_depth)
  48.    {
  49.       this.min = t_depth;
  50.       this.max = t_depth + this.numSlots;
  51.       this.reset();
  52.       return this.max;
  53.    }
  54.    function reset()
  55.    {
  56.       this.mcs = [];
  57.       if(this.reverse)
  58.       {
  59.          this.current = this.max;
  60.       }
  61.       else
  62.       {
  63.          this.current = this.min;
  64.       }
  65.    }
  66.    function requestDepthChange(t_element)
  67.    {
  68.       t_element.mc.swapDepths(this.__getChangedDepth(t_element));
  69.    }
  70.    function requestDepthSort()
  71.    {
  72.       trace("Request Depth Sort not implemented yet. Better get to work!");
  73.    }
  74.    function getDepth(t_depth)
  75.    {
  76.       if(this.sortAxis != "")
  77.       {
  78.          return this.__getNewDepth(t_depth);
  79.       }
  80.       this.increment();
  81.       return this.current;
  82.    }
  83.    function increment()
  84.    {
  85.       this.isSearching = true;
  86.       while(this.isSearching)
  87.       {
  88.          if(this.reverse)
  89.          {
  90.             this.current = this.current - 1;
  91.             if(this.current < this.min)
  92.             {
  93.                this.current = this.max;
  94.             }
  95.          }
  96.          else
  97.          {
  98.             this.current = this.current + 1;
  99.             if(this.current > this.max)
  100.             {
  101.                this.current = this.min;
  102.             }
  103.          }
  104.          this.isSearching = false;
  105.          this.loop = this.mcs.length;
  106.          while(this.loop--)
  107.          {
  108.             if(this.mcs[this.loop].depth == this.current)
  109.             {
  110.                this.isSearching = true;
  111.                this.loop = 0;
  112.             }
  113.          }
  114.       }
  115.    }
  116.    function __getNewDepth(depth)
  117.    {
  118.       if(depth < 0)
  119.       {
  120.          trace("Error : Depth cannot be under zero");
  121.          return undefined;
  122.       }
  123.       if(this.ascending)
  124.       {
  125.          depth = this.min + Math.ceil(depth);
  126.       }
  127.       else
  128.       {
  129.          depth = this.max - Math.ceil(depth);
  130.       }
  131.       this.loop = this.mcs.length;
  132.       while(this.loop--)
  133.       {
  134.          if(this.mcs[this.loop].depth == depth)
  135.          {
  136.             if(this.ascending)
  137.             {
  138.                depth = depth + 1;
  139.             }
  140.             else
  141.             {
  142.                depth = depth - 1;
  143.             }
  144.             this.loop = this.mcs.length;
  145.          }
  146.       }
  147.       return depth;
  148.    }
  149.    function __getChangedDepth(t_element)
  150.    {
  151.       var _loc2_ = Math.ceil(t_element[this.sortAxis]);
  152.       if(_loc2_ < 0)
  153.       {
  154.          trace("Error : Depth cannot be under zero");
  155.          return undefined;
  156.       }
  157.       if(this.ascending)
  158.       {
  159.          _loc2_ = this.min + _loc2_;
  160.       }
  161.       else
  162.       {
  163.          _loc2_ = this.max - _loc2_;
  164.       }
  165.       var _loc3_ = -1;
  166.       this.loop = this.mcs.length;
  167.       while(this.loop--)
  168.       {
  169.          if(this.mcs[this.loop].mc == t_element.mc)
  170.          {
  171.             _loc3_ = this.loop;
  172.          }
  173.          else if(this.mcs[this.loop].depth == _loc2_)
  174.          {
  175.             if(this.ascending)
  176.             {
  177.                _loc2_ = _loc2_ + 1;
  178.             }
  179.             else
  180.             {
  181.                _loc2_ = _loc2_ - 1;
  182.             }
  183.             this.loop = this.mcs.length;
  184.          }
  185.       }
  186.       this.mcs[_loc3_].depth = _loc2_;
  187.       return _loc2_;
  188.    }
  189. }
  190.